import React from "react"
import { Route, Redirect } from "react-router-dom"
// 导入token设置
import { getToken } from "utils/settingToken"


function AuthRouter({ component: Component, ...rest }) {
    return (
        <Route
            {...rest}
            render={(props) => {
                // console.log("props", props)
                const hasToken = getToken()
                if (hasToken) {
                    return <Component {...props}></Component>
                } else {
                    return (
                        //             重定向
                        //   重哪里来就跳回去
                        < Redirect
                            to={{ pathname: "/login", state: { from: props.location } }
                            }
                        />
                    )
                }
            }}
        ></Route >
    )
}

export default AuthRouter